package cn.thr.pethome.myListener;

import cn.thr.pethome.permission.mapper.PermissionMapper;
import cn.thr.pethome.permission.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener  //交给springboot 启动的时候让他在知道
public class PermissionScanInitListener implements ServletContextListener {

    @Autowired
    private IPermissionService permissionService;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
       //线程 开启另外一个线程用来扫描
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("初始化开始********************");
                permissionService.automaticScanning();  //自动执行角色扫描
                System.out.println("初始化结束********************");
            }
        }).start();
    }
}
